<?php

namespace App\Models\Kms\Task;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class TaskModel extends BaseModel
{
    use HasFactory;

    protected $table = "kms_task";

    protected $fillable = [
        "businessId",
        "templateId",
        "status",
        "createdByUid",
        "updatedByUid"
    ];


    const TASK_STATUS_INVALID  = 0;
    const TASK_STATUS_ING      = 1;
    const TASK_STATUS_FINISHED = 2;

    const TASK_STATUS_TEXT = [
        self::TASK_STATUS_INVALID  => "已作废",
        self::TASK_STATUS_ING      => "进行中",
        self::TASK_STATUS_FINISHED => "已完成",
    ];

    /**
     * @return HasMany
     */
    public function taskNodesRel(): HasMany
    {
        return $this->hasMany(TaskNodesModel::class, "taskId", "id")->orderBy("id");
    }

    /**
     * @return HasOne
     */
    public function templateRel(): HasOne
    {
        return $this->hasOne(TaskTemplateModel::class, "id", "templateId");
    }

    /**
     * @return HasOne
     */
    public function dailyTaskLogsRel(): HasOne
    {
        return $this->hasOne(DailyTaskLogsModel::class, "id", "businessId");
    }
}
